<%--
 *  File:    DBManagerInfo.jsp
 *  @Author: TerryCui
 *  Date:    2010/9/11
--%>

<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="com.oval.util.JspHelper" %>

<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  	//init param
  	Category cat = Category.getInstance("jsp.DBManagerInfo");  
  	String privilegeCode = "";
  	String contextPath = request.getContextPath();
  	String strModuleName = "COM";
  	request.getSession(true);
%>

<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title>DBManagerInfo</title>
<PageFlow:CheckPageFlow pageName="p_dbmanagerinfo"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/console/css/chinese/csscontent.css" type="text/css"> 
<script language="JavaScript" src="<%=contextPath%>/css/cn/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/FuncLib.js"></script>
<%
	HashMap serviceInfo = (HashMap)pageContext.getAttribute("serviceinfo");
	Integer serviceid = (Integer)(serviceInfo.get("serviceid"));
	int n1stPCheck = ((Integer)(serviceInfo.get("parameter1check"))).intValue();
	int n2ndPCheck = ((Integer)(serviceInfo.get("parameter2check"))).intValue();
	int nPCount = 0;
	
	if(n1stPCheck != 0){
		nPCount = nPCount + 1;
	}
	if(n2ndPCheck != 0){
		nPCount = nPCount + 1;
	}
%>
<script>
function toggle(tbody){
	if(tbody == "parameter"){
		if(parametersHide.style.display=='none'){
			parametersHide.style.display = 'inline';
			parametersShow.style.display = 'none';
		}
		else{
			parametersShow.style.display = 'inline';
			parametersHide.style.display = 'none';
		}
	}else if(tbody == "commanddemo"){
		if(commandDemoHide.style.display=='none'){
			commandDemoHide.style.display = 'inline';
			commandDemoShow.style.display = 'none';
		}
		else{
			commandDemoShow.style.display = 'inline';
			commandDemoHide.style.display = 'none';	
			replaceSql();
		}
	}
}

function replaceSql(){
	var n_sql = o_sql;
	var p1check = <%=n1stPCheck%>;
	var p1value = "";
	if(p1check != 0){
		p1value = document.getElementById("parameter1value").value;
		n_sql = n_sql.replace(new RegExp("v_parameter1","gm"),p1value);		
	}
	
	var p2check = <%=n2ndPCheck%>;
	var p2value = "";
	if(p2check != 0){
		p2value = document.getElementById("parameter2value").value;
		n_sql = n_sql.replace(new RegExp("v_parameter2","gm"),p2value);	
	}
	
	document.getElementById("td_sql").innerHTML = n_sql;
}

function page_execute(){
	var p1check = <%=n1stPCheck%>;
	var p1value = "";
	if(p1check != 0)
		p1value = document.getElementById("parameter1value").value;
	if(p1check == 1 && p1value == ""){
		alert("1st parameter can not be empty!");
		parametersShow.style.display = 'inline';
		parametersHide.style.display = 'none';		
		return;
	}

	var p2check = <%=n2ndPCheck%>;
	var p2value = "";
	if(p2check != 0)
		p2value = document.getElementById("parameter2value").value;
	if(p2check == 1 && p2value == ""){
		alert("2nd parameter can not be empty!");
		parametersShow.style.display = 'inline';
		parametersHide.style.display = 'none';		
		return;
	}	
	var serviceid = "<%=serviceid%>";
	var url = "DBManagerAction.jsp?serviceid=" + serviceid + "&p1check=" + p1check + "&p1value=" + p1value + "&p2check=" + p2check + "&p2value=" + p2value;
	self.location.href = url;
}
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<input type="hidden" name="actionname">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td background="images/chinese/title_bg.gif"><img src="images/chinese/title_bg.gif" width="3" height="29"></td>
  </tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr> 
		<td class="red_title">Service Name: &nbsp;</td>
		<td><custom:write name="serviceinfo" property="servicename"/></td>
	</tr>
	<tr> 
		<td class="td_bg_row">&nbsp;</td>
		<td class="td_bg_row">&nbsp;</td>
	</tr>
</table>

<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999">
	<tbody id="parametersHide" onclick="toggle('parameter')" style="display:inline;">
		<tr> 
			<td colspan="4" class="td_title_bg"><img src="<%=contextPath%>/console/images/chinese/arrow3.gif"> 
				<%=JspHelper.filterNull( nPCount )%> Creation Parameter<%if(nPCount != 1){%>s<%}%>
			</td>
		</tr>
	</tbody>
	<tbody id="parametersShow" style="display:none;">
		<tr onclick="toggle('parameter')"> 
			<td colspan="4" class="td_title_bg"><img src="<%=contextPath%>/console/images/chinese/arrow2.gif">Creation Parameters</td>
		</tr>
		  
		<% if(nPCount == 0){ %>
			<tr>
				<td>None</td>
			</tr>
		<%}%>
		<% if(nPCount >= 1){ %>
			<tr class="td_bg1">
			 	<td width="20%">1th Parameter Name:</td>
			 	<td width="30%"><custom:write name="serviceinfo" property="parameter1name" nbsp="true"/></td>
			 	<td width="20%">1th Parameter Type:</td>
			 	<td width="30%"><custom:write name="serviceinfo" property="parameter1type" nbsp="true"/></td>
		 	</tr>
			<tr class="td_bg1">
			 	<td width="20%">1th Parameter Value:</td>
			 	<td width="30%"><custom:text name="serviceinfo" property="parameter1value" onblur="replaceSql()" onkeydown="javascript:if(window.event.keyCode == 13)replaceSql();"/></td>
			 	<td width="20%">1th Parameter Desc:</td>
			 	<td width="30%"><custom:write name="serviceinfo" property="parameter1desc" nbsp="true"/></td>
		 	</tr>
		<%}%>
		<% if(nPCount >= 2){ %>
			<tr class="td_bg1">
			 	<td width="20%">2nd Parameter Name:</td>
			 	<td width="30%"><custom:write name="serviceinfo" property="parameter2name" nbsp="true"/></td>
			 	<td width="20%">2nd Parameter Type:</td>
			 	<td width="30%"><custom:write name="serviceinfo" property="parameter2type" nbsp="true"/></td>
		 	</tr>
			<tr class="td_bg1">
			 	<td width="20%">2nd Parameter Value:</td>
			 	<td width="30%"><custom:text name="serviceinfo" property="parameter2value" onblur="replaceSql()" onkeydown="javascript:if(window.event.keyCode == 13)replaceSql();"/></td>
			 	<td width="20%">2nd Parameter Desc:</td>
			 	<td width="30%"><custom:write name="serviceinfo" property="parameter2desc" nbsp="true"/></td>
		 	</tr>
		<%}%>
	</tbody>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td rowspan="2" bgcolor="999999" width="1"></td>
    <td height="12">&nbsp;</td>
    <td rowspan="2" width="13"><img src="<%=contextPath%>/console/images/chinese/corner.gif"></td>
  </tr>
  <tr> 
    <td bgcolor="999999" height="1"></td>
  </tr>
  <tr> 
    <td height="10" colspan="3"></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td height="10"></td>
    <td></td>
  </tr>
</table>

<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999">
	<tbody id="commandDemoHide" onclick="toggle('commanddemo')" style="display:inline;">
		<tr> 
			<td class="td_title_bg"><img src="<%=contextPath%>/console/images/chinese/arrow3.gif"> 
				Command Demo
			</td>
		</tr>
	</tbody>
	<tbody id="commandDemoShow" style="display:none;">
		<tr onclick="toggle('commanddemo')"> 
			<td class="td_title_bg"><img src="<%=contextPath%>/console/images/chinese/arrow2.gif">Command Demo</td>
		</tr>
		<tr class="td_bg1">
			<td id="td_sql"><custom:write name="serviceinfo" property="servicesql"/></td>
		</tr>
		<tr class="td_bg1">
			<td><input type="button" name="EXECUTE" value="EXECUTE" onclick="javascript:page_execute()"></td>
		</tr>		
	</tbody>
</table>
<script>
var o_sql = document.getElementById("td_sql").innerHTML;
</script>
</body>
</html>


